@extends('base')

@section('content')
    <div class="layui-card">
        <div class="layui-card-body">
            <table id="dataTable" lay-filter="dataTable"></table>
            <script type="text/html" id="options">
                <div class="layui-btn-group">
                    @can('crm.customer.show')
                        <a class="layui-btn layui-btn-sm" lay-event="show">详情</a>
                    @endcan
                    @can('crm.customer.remark')
                        <a class="layui-btn layui-btn-sm" lay-event="remark">跟进</a>
                    @endcan
                </div>
            </script>
            <script type="text/html" id="call_phone">
                <span style="display: inline-block;width: 80px">@{{d.contact_phone}}</span>
                <i class="layui-icon layui-icon-cellphone-fine" onclick="call('@{{d.contact_phone}}')" title="点击呼叫" style="cursor: pointer"></i>
            </script>
        </div>
    </div>
@endsection

@section('script')
    <script>
        layui.use(['layer','table','form','laydate','dropdown'],function () {
            var $ = layui.jquery;
            var dropdown = layui.dropdown
            var layer = layui.layer;
            var form = layui.form;
            var table = layui.table;
            var laydate = layui.laydate;
            //用户表格初始化
            var dataTable = table.render({
                elem: '#dataTable'
                ,height: 'full-40'
                ,url: "{{ route('index.customer') }}" //数据接口
                ,page: true //开启分页
                ,cols: [[ //表头
                    {checkbox: true}
                    ,{field: 'uuid', title: '客户编号',width:160,templet:function (d) {
                            return '<a lay-event="show" style="cursor: pointer;color: green" title="点击查看">'+ d.uuid+ '</a>'
                        }}
                    ,{field: 'name', title: '客户名称',width:120}
                    ,{field: 'contact_name', title: '联系人',width:100}
                    ,{field: 'contact_phone', title: '联系电话',width:140,toolbar:'#call_phone'}
                    ,{field: 'type_name', title: '分类',width:100}
                    ,{field: 'node_name', title: '当前进度',width:100}
                    ,{field: 'follow_time', title: '跟进时间',width:160}
                    ,{field: 'follow_user_nickname', title: '跟进人',width:100}
                    ,{field: 'remark', title: '跟进备注'}
                    ,{fixed: 'right', width: 180, align:'center', toolbar: '#options', title:'操作'}
                ]]
            });

            //监听工具条
            table.on('tool(dataTable)', function(obj){ //注：tool是工具条事件名，dataTable是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                    ,layEvent = obj.event; //获得 lay-event 对应的值
                var id = data.id;
                if (layEvent === 'show'){
                    layer.open({
                        type: 2,
                        title: "详情",
                        shadeClose: true,
                        area: ["90%","90%"],
                        content: '/crm/customer/'+id+'/show',
                    })
                } else if(layEvent === 'remark') {
                    layer.open({
                        type: 2,
                        title: "备注",
                        shadeClose: true,
                        area: ["80%","90%"],
                        content: '/crm/customer/'+id+'/remark',
                    })
                }

            });



        })
    </script>
@endsection
